//
//  JYTAppointViewController.m
//  JYT_IOS
//
//  Created by nxa-chengjinhui on 2017/1/6.
//  Copyright © 2017年 nxa-yuanguoxiang. All rights reserved.
//

#import "JYTAppointViewController.h"
#import "JYTAppointTableViewCell.h"
#import "JYTAppointRequest.h"
#import "JYTMineUserClass.h"
#import "JYTTrainDetailViewController.h"
@interface JYTAppointViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *tabview;

@property (nonatomic,strong) NSArray *dataArray;

@end

@implementation JYTAppointViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    NSDictionary *dic = @{@"lftBtnBgImg":@"ic_goback",
                          @"lftBtnTitle":@"no",
                          @"pageTitle":@"预约",
                          @"rhtBtnBgImg":@"",
                          @"rhtBtnTitle":@"no"};
    
    [self setNavgationBarWithDic:dic];
    
    [self getData];
    
    [self chooseView];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
}
-(void)getData{
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setObject:[[[JYTUserManager shared] getUser] school].drivingSchoolId forKey:@"DrivingSchoolId"];
    [dic setObject:@"1" forKey:@"PageNo"];
    [dic setObject:@"10" forKey:@"PageSize"];
    [dic setObject:@"GetCoach" forKey:@"CommandCode"];
    
    [[JYTAppointRequest shareAppoint] getdata:dic completed:^(BOOL success) {
        if (success) {
            [self.tabview reloadData];
        }
    }];
}

-(void)chooseView{
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 64, CURRENT_SCREEN_WIDTH, 44)];
    view.backgroundColor = [UIColor redColor];
    [self.view addSubview:view];
    
    self.tabview = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(view.frame), CURRENT_SCREEN_WIDTH, CURRENT_SCREEN_HEIGHT-64 - view.frame.size.height) style:UITableViewStylePlain];
    self.tabview.delegate = self;
    self.tabview.dataSource = self;
    self.tabview.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
//    [self.tabview registerClass:[JYTAppointTableViewCell class] forCellReuseIdentifier:@"trainCell"];
    [self.tabview registerNib:[UINib nibWithNibName:NSStringFromClass([JYTAppointTableViewCell class]) bundle:nil] forCellReuseIdentifier:@"trainCell"];
    [self.view addSubview:self.tabview];
}
#pragma mark---UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 8;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    JYTAppointTableViewCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"JYTAppointTableViewCell" owner:nil options:nil] firstObject];
    JYTAppointTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"trainCell"];
    
    cell.model = [JYTMineUserClass shareUserClass].arr[indexPath.row];
    
    return cell;
}
#pragma mark---UITableViewDelegate
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 140;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    JYTAppointTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
    [self pushViewController:[[JYTTrainDetailViewController alloc] initWithModel:cell.model]];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
